package org.example.demo3.common;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.example.demo3.info.Articleinfo_plus;
import org.example.demo3.info.Userinfo;
import org.example.demo3.mapper.Articlemapper;
import org.example.demo3.mapper.UserMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;

//优质作者算法
@Component
public class Hot_count {
    @Resource
    private Articlemapper articlemapper;
    @Resource
    private UserMapper userMapper;
    public List<Articleinfo_plus> final_hot_article(){
        List<Articleinfo_plus> list=hot_article_count();
        list.sort(new Comparator<Articleinfo_plus>() {
            @Override
            public int compare(Articleinfo_plus o1, Articleinfo_plus o2) {
                return o2.getHot_count()-o1.getHot_count();
            }
        });
        return list;
    }
    public List<Articleinfo_plus> hot_article_count(){
        List<Articleinfo_plus> list=articlemapper.get_all_article();
        for (int i=0;i<list.size();i++){
            if (list.get(i).getTitle().length()>6){
                list.get(i).setTitle(list.get(i).getTitle().substring(0,6));
            }
            Articleinfo_plus articleinfoPlus=articlemapper.hot_count(list.get(i).getId(),list.get(i).getId(),list.get(i).getId());
            list.get(i).setHot_count((int)(articleinfoPlus.getRcount()*0.3)+articleinfoPlus.getReview_count()*3+articleinfoPlus.getResponse_count()*4);
        }
        return list;
    }
}
